package com.biyabi.config;/*
package com.baizhi.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.DigestUtils;
import redis.clients.jedis.Jedis;

@Configuration
@Aspect
public class RedisCacheConfig {
    @Autowired
    private Jedis jedis;

    @AfterReturning("execution(* com.baizhi.service.impl.*.do*(..))")
    public void flush(){
        jedis.flushDB();
    }

    @Around("execution(* com.baizhi.service.impl.*.find*(..))")
    public Object around(ProceedingJoinPoint proceedingJoinPoint){
        MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
        String key = getKey(proceedingJoinPoint);
        Object result = null;
        if(jedis.exists(key)){
            result = JSONObject.parseObject(jedis.get(key), signature.getMethod().getReturnType());
        }else{
            try {
                result = proceedingJoinPoint.proceed();
                String json = JSONObject.toJSONStringWithDateFormat(result,"yyyy-MM-dd");
                result = JSONObject.parseObject(json, signature.getMethod().getReturnType());
                jedis.set(key,JSONObject.toJSONStringWithDateFormat(result,"yyyy-MM-dd"));
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
        return result;
    }

    public String getKey(ProceedingJoinPoint proceedingJoinPoint){
        StringBuilder builder = new StringBuilder();
        String clazzName = proceedingJoinPoint.getTarget().getClass().getName();
        String methodName = proceedingJoinPoint.getSignature().getName();
        builder.append(clazzName).append(methodName);
        Object[] args = proceedingJoinPoint.getArgs();
        for (Object arg : args) {
            builder.append(arg);
        }
        return DigestUtils.md5DigestAsHex(builder.toString().getBytes());
    }
}
*/
